#include "waitPage.h"
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMovie>
#include <ElaProgressBar.h>
#include <ElaTheme.h>
#include <ElaText.h>

waitPage::waitPage(QWidget* parent)
    : ElaWidget(parent)
{
    setWindowTitle("进度...");
    setWindowIcon(QIcon(":/include/Image/liu.jpg"));
    setWindowButtonFlags(ElaAppBarType::CloseButtonHint);
    setWindowModality(Qt::WindowModality::ApplicationModal);
    setWindowFlags(windowFlags() | Qt::Dialog);
    setIsFixedSize(true);
    setFixedSize(400, 100);

    status_ = new ElaText();
    status_->setText("正在创建Word");
    status_->setTextPixelSize(10);
    status_->setFixedWidth(65);
    progress_ = new ElaProgressBar();
    progress_->setMinimum(0);
    progress_->setMaximum(100);
    progress_->setFixedWidth(170);
    progress_->setTextVisible(false);
    progressText_ = new ElaText();
    progressText_->setTextPixelSize(10);
    progressText_->setText("0.00%");
    QHBoxLayout *statusLayout = new QHBoxLayout();
    statusLayout->addWidget(status_);
    statusLayout->addWidget(progress_);
    statusLayout->addWidget(progressText_);

    mv_ = new ElaText();
    QMovie *carMv = new QMovie(":/Image/mv/car.gif");
    mv_->setMovie(carMv);
    mv_->setScaledContents(true);
    mv_->setFixedSize(80, 80);
    carMv->start();

    QHBoxLayout *mainLayout = new QHBoxLayout(this);
    mainLayout->addWidget(mv_);
    mainLayout->addSpacing(20);
    mainLayout->addLayout(statusLayout);
    mainLayout->addStretch();

    hide();
    connect(eTheme, &ElaTheme::themeModeChanged, this, [=]() {
        if (!parent) {
            update();
        }
    });
}

void waitPage::onWordSuccessCreated()
{
    status_->setText("正在导出歌词");
}

void waitPage::onExportProgressChanged(int total, int current)
{
    double value = (double)current / total * 100;
    progress_->setValue(value);
    progressText_->setText(QString::number(value, 'f', 2) + "%");
}
